<?php
namespace Index\Controller;
use Think\Controller;
header("Content-type: text/html; charset=utf-8");
	//个人主页
class PeopleController extends Controller {	
  	public function IndexAction(){         
  		// $uid = $_SESSION['id'];
      $uid=I('get.uid');
      // var_dump($uid);
      // exit();
  		//查找该用户信息表（头像、用户名、介绍等）
  		$user_sql="select * from user where id='$uid'";
  		$data_m=M();
  		$user_res=$data_m->query($user_sql);
  		
  		//该用户回复过的问题及回复的内容
  		$question_answer_sql="select * from question t1 left join answer t2 on t1.id=t2.qid where t2.uid='$uid'";
  		$question_answer_res=$data_m->query($question_answer_sql);

  		//该用户所发的问题
  		$question_sql="select * from question where uid='$uid'";
  		$question_res=$data_m->query($question_sql);
  		// var_dump($question_res);
  		// exit();
      //获取动态链接数据
      $sql="select t1.send_replay_question,t1.time,t2.head_img,t2.username,t3.title,t3.replay_num,t4.centent from log t1 left join user t2 on t1.uid=t2.id left join question t3 on t1.qid=t3.id left join answer t4 on t1.replay_id=t4.id order by t1.time desc limit 2";
      $Dynamic_res=$data_m->query($sql);
      // var_dump($Dynamic_res);
      // exit();
      //主页被访问师view+1
      $page_sql="update user set view=view+1 where id=$uid";
      $data_m->execute($page_sql);
      //读取user中view的值
      $read_user_sql="select view from user where id=$uid";
      $page_res=$data_m->query($read_user_sql);
      $page_res=current($page_res);
      // var_dump($page_res);
      // exit();
      $this->assign('page_res',$page_res);//获取动态数据分配到模板
      $this->assign('Dynamic_res',$Dynamic_res);//获取动态数据分配到模板
  		$this->assign('user_res',$user_res);//问题与回复分配页
  		$this->assign('question_answer_res',$question_answer_res);//问题与回复分配页
		  $this->assign('question_res',$question_res);//该用户所发问题分配页
  		$this->display();
  	 }

}
?>